<script setup lang='ts'>
import {loginAPI, FlashSessionListApi} from '../../request/api'
import {onMounted, ref} from 'vue';

const size = ref(20)
const selectedGame = ref<string>('');
const selectedDate = ref<Date>(new Date());
const gameList = [
    {
        value: '敢不敢来玩',
        label: '敢不敢来玩'
    },
    {
        value: '这游戏真难',
        label: '这游戏真难'
    },
    {
        value: '骚操作',
        label: '骚操作'
    },
    {
        value: '就是爱玩',
        label: '就是爱玩'
    },
    {
        value: '谁都爱玩',
        label: '谁都爱玩'
    },
]
const tableData = ref<Array<{ id: string; cost: number; eventName: string; eventTime: string; openId: string }>>([]);
const totalCost = ref<number>(0);
const currentPage = ref<number>(1);
const pageSize = ref<number>(10);
const total = ref<number>(0);

//加载挂载一次
let listArr = ref([])
onMounted(() => {
    init()
})

//**//初始函数 init 渲染数据列表
const init = async () => {
    let res = await FlashSessionListApi()
    // listArr=res
    console.log(res);

}
const query = async () => {
    // 查询数据的逻辑
    console.log('查询');


    let res = await FlashSessionListApi()
    console.log(res);


};

const queryECPM = () => {
    // 查询ECPM的逻辑
    console.log('查询ECPM');
};

const handleSizeChange = (val: number) => {
    console.log(`${val} items per page`);
};

const handleCurrentChange = (val: number) => {
    console.log(`current page: ${val}`);
};

const value = ref('')

const options = [
    {
        value: 'Option1',
        label: 'Option1',
    },
    {
        value: 'Option2',
        label: 'Option2',
    },
    {
        value: 'Option3',
        label: 'Option3',
    },
    {
        value: 'Option4',
        label: 'Option4',
    },
    {
        value: 'Option5',
        label: 'Option5',
    },
]
</script>
<template>
    <div>
        <el-slider v-model="size"/>
        <el-container class="app-container custom-container">
            <el-header class="header">
                <el-space wrap :size="size">
                    <el-select v-model="selectedGame" placeholder="游戏:" style="width: 240px" class="select">
                        <el-option
                            v-for="item in gameList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                    <el-date-picker v-model="selectedDate" type="date" placeholder="选择日期"
                                    class="date-picker"></el-date-picker>
                    <el-button @click="query" class="button" type="success">查询</el-button>
                    <el-button @click="queryECPM" class="button" type="success">查询ECPM</el-button>
                    ECPM:
                    总收入
                </el-space>
            </el-header>
            <el-main class="main">
                <div class="table-container">
                    <el-table :data="tableData" style="width: 100%">
                        <el-table-column prop="id" label="ID" width="180"></el-table-column>
                        <el-table-column prop="cost" label="Cost" width="180"></el-table-column>
                        <el-table-column prop="eventName" label="Event Name" width="180"></el-table-column>
                        <el-table-column prop="eventTime" label="Event Time" width="180"></el-table-column>
                        <el-table-column prop="openId" label="Open ID" width="180"></el-table-column>
                    </el-table>
                </div>
                <div style="margin-top: 20px;">
                    <span>总费用: {{ totalCost }}</span>
                </div>
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                ></el-pagination>
            </el-main>
        </el-container>
    </div>
</template>
